#include <iostream>
#include <map>
#include <math.h>
using namespace std;
const int day[6]={1,3,7,30,120,365};


int main(){
	int n,ans=0;
	cin>>n;
	map<int,int> mp;
	for(int i=0;i<6;i++){
		int v;
		cin>>v;
		mp[day[i]] = v+1;
	}
	int sum=0,v=0;
	for(int i=0;i<n;i++){
		int online;
		cin>>online;
		if(online){
			sum++;
			if(mp[sum] != 0)
				v = mp[sum]-1;
			ans += v;
		}
		else{
			sum = 0;
			v = 0;
		}
	}
	cout<<ans;
	return 0;
}
